const express = require('express');
const session = require('express-session');
const cors = require('cors');
const app = express();
const userApi = require('./userApi');
const  addressApi = require('./addressApi')
const goodsApi = require('./goodsApi')
const imgApi = require("./imgApi")
const orderApi = require("./orderApi")
const router = express.Router();
const path = require('path');

// 允许所有来源的请求
const corsOptions = {
  origin: 'http://localhost:8080',
  credentials: true
};


app.use(cors(corsOptions));
app.use("/static",express.static('static'));

// 配置session
app.use(session({
  secret: 'your_session_secret',
  resave: false,
  saveUninitialized: true,
  cookie: { secure: false } // 设置为 true，要求在 HTTPS 环境下使用 Cookie
}));

// 添加中间件来解析请求体
app.use(express.json());

// 使用用户API路由
app.use('/api/user', userApi);
app.use('/api/address',addressApi)
app.use('/api/imglist',imgApi)
app.use('/api/goods',goodsApi)
app.use('/api/order',orderApi)

// 启动服务器
const port = 3000;
app.listen(port, () => {
  console.log(`服务器已启动，正在监听端口 ${port}`);
});
